/*
@Copyright:LintCode
@Author:   tjyemail
@Problem:  http://www.lintcode.com/problem/reverse-words-in-a-string
@Language: C++
@Datetime: 16-02-09 05:17
*/

class Solution {
    void reverse(char *str){
        int i=0,j=strlen(str)-1;
        char c;
        while(i<j){
            c = str[i];
            str[i]=str[j];
            str[j]=c;
            ++i,--j;
        }
    }
public:
    /**
     * @param s : A string
     * @return : A string
     */
    string reverseWords(string &s) {
        // write your code here
        stringstream istr(s);
        char res[10000]="",str[100]="";
        while(istr>>str){
            reverse(str);
            strcat(res,str);
            strcat(res," ");
        }
        reverse(res);
        return res+1;
    }
};